package com.youlu.campus.web.community.controller;

import com.youlu.campus.web.community.dto.ArticlePageResponse;
import com.youlu.campus.web.community.dto.ArticleResponse;
import com.youlu.campus.web.community.dto.TopicQueryRequest;
import com.youlu.campus.web.community.service.ArticleService;
import com.yuelin.infrastructure.quantum.common.QResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 文章信息API
 *
 * @author: YangJ
 * @date: 2020/11/24 18:05
 */
@RestController
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     * 文章列表API
     * 备注：社区主页文章取前4条,文章列表分页取
     * 参数：request - 文章信息查询请求类
     * 返回：200-请求成功，返回ArticlePageResponse类型结果
     */
    @PostMapping("/mini-app/article/page")
    public QResult articlePage(@RequestBody TopicQueryRequest request) {
        return QResult.success(articleService.articleList(request));
    }

    /**
     * 文章详情查询API
     * 备注：文章详情页使用
     * 参数：id - 文章ID
     * 返回：200-请求成功，返回ArticleResponse类型结果
     */
    @GetMapping("/mini-app/article/query")
    public QResult article(String id) {
        return QResult.success(articleService.query(id));
    }
}